Skip to main content

Loops

Loops allow a BindAI workflow to repeat an operation or group of operations while a runtime decision indicates that another iteration should occur. Loops are useful when the same workflow logic must execute repeatedly, such as processing items, repeating validation, or continuing work until a condition is satisfied. BindAI V1 supports loop-based workflow execution as part of its workflow control-flow capabilities. The exact public API for defining workflow loops should be taken from the installed BindAI implementation.

What Is a Loop?

A loop creates repeated execution within a workflow. Conceptually:
The loop determines whether another iteration should execute. After the loop body completes, execution can return to the loop decision.

Why Use Loops?

Loops are useful when workflow logic must execute repeatedly. Common examples include:
  • Processing collections
  • Processing batches
  • Repeated validation
  • Iterative analysis
  • Processing paginated data
  • Incremental synchronization
  • Repeating an operation until a desired state is reached
Without loop behavior, repeated workflow logic would need to be duplicated or manually represented through graph structure.

Loop Execution Flow

A typical loop follows this pattern:
When the continuation decision is true, the workflow executes the loop body. After the body completes, the workflow evaluates the decision again. When the decision becomes false, execution leaves the loop.

Loop State

Loops normally depend on information that changes as execution progresses. For example:
The loop body should make progress toward its terminating state. If the state used by the loop decision never changes, the workflow may continue indefinitely.

Loop Body

The loop body contains the operations performed during one iteration. For example:
A loop body can contain multiple workflow operations, including:
  • Agents
  • Tools
  • Conditions
  • Application processing
  • Validation
  • Connection-backed tools
The body should remain focused on the work required for one iteration.

Loop Decisions

The continuation decision determines whether another iteration should occur. Conceptually:
The decision can depend on values produced during workflow execution. For example, a workflow may continue while:
  • More items remain
  • A task is incomplete
  • A validation condition is not satisfied
  • Additional pages are available
  • Additional work remains
The exact decision expression and configuration should follow the implemented BindAI workflow API.

Example: Processing a Collection

A common loop pattern processes items one at a time.
Conceptually, the workflow may maintain:
The continuation decision checks whether another item remains. For example:
The loop body processes the current item and advances the workflow state.

Example: Batch Processing

Loops can process batches incrementally.
The continuation decision determines whether another batch remains. This can keep each iteration focused on a manageable unit of work.

Example: Pagination

A workflow can repeatedly process pages of data.
The workflow can use pagination information returned by an operation to determine whether another iteration is required.

Example: Repeated Validation

A workflow may repeat processing until a desired state is reached.
The workflow should have a reliable termination mechanism when the state being evaluated is unpredictable.

Loops with Conditions

Conditions can participate inside a loop.
The loop controls repetition. The condition controls a decision within the iteration. This is useful when each iteration can have multiple outcomes.

Loops with Agents

An Agent node can participate in each loop iteration. For example:
This can be useful for:
  • Iterative analysis
  • Classification of multiple items
  • Repeated planning
  • Processing a collection of requests
The workflow should still provide a clear termination mechanism independently of the model’s output.

Loops with Tools

Tool nodes are useful when each iteration performs deterministic work.
Examples include:
  • Processing records
  • Calling an API for each item
  • Performing calculations
  • Writing application data
  • Synchronizing external resources
Tool execution remains responsible for the operation itself, while the workflow controls iteration.

Loops with Connection-Backed Tools

A loop can repeatedly execute a connection-backed tool. For example:
This can be useful when an application needs to perform the same external operation for multiple workflow items. In BindAI V1, Webhook is the implemented Studio connection provider.

Loops with Knowledge

An Agent node inside a loop can use configured Knowledge during each iteration. For example:
This can be useful when each item requires separate contextual analysis. Knowledge remains responsible for providing searchable information, while the workflow controls iteration.

Loops with Memory

An Agent node inside a loop can also use configured Memory. For example:
Memory can preserve information for agent interactions. Workflow state, meanwhile, carries information required by the current workflow execution.

Nested Loops

Loops can conceptually be combined with other loops. For example:
A common example is hierarchical data:
Nested loops can be useful, but excessive nesting can make workflows difficult to understand and debug.

Avoiding Unbounded Loops

Every loop should have a reliable path toward termination. For example:
Eventually:
The important property is that the loop body changes the state used by the continuation decision.

Loop Progress

A useful loop should make measurable progress. For example:
Progress can be represented by:
  • An item position
  • A page number
  • A batch identifier
  • A completion flag
  • Remaining work
  • Application state
Making progress explicit helps prevent accidental non-termination.

Loop State and Workflow Variables

Loop state can be stored in workflow variables. For example:
A typical flow is:
The variables required by the loop should be initialized before the loop begins.

Loop Exit

Every loop should have a clear exit path.
The exit path allows downstream workflow operations to continue after iteration is complete. A loop without a reachable exit can cause unbounded workflow execution.

Loop and Retry Are Different

Loops and retries both involve repeated execution, but they represent different concepts. Use a loop when repetition is part of the intended workflow behavior. Retry is a separate capability and is outside the verified advanced V1 workflow scope.

Error Handling Inside Loops

A failure inside a loop body can affect the workflow execution. For example:
The application should define appropriate failure behavior for important loop operations. For V1, do not assume that every loop automatically retries failed operations.

Testing Loops

Loop behavior should be tested across several scenarios.

Zero iterations

The continuation decision is initially false.
The loop body should not execute.

One iteration

The decision is initially true but becomes false after one iteration.

Multiple iterations

The decision remains true for several iterations before becoming false.

Non-terminating state

The continuation decision never becomes false. This should be treated as an invalid workflow design or execution condition that requires an appropriate application-level safeguard.

Testing Loop State

Tests should verify that workflow state changes as expected. For example:
This verifies both the loop body and its termination condition.

Loop Design Pattern

A reliable loop generally follows this pattern:
The important property is that the body changes the state used by the continuation decision. That creates measurable progress toward termination.

Common Use Cases

Loop behavior is useful for:
  • Collection processing
  • Batch processing
  • Pagination
  • Iterative validation
  • Incremental synchronization
  • Repeated agent processing
  • Repeated tool operations
  • Processing remaining work
  • Iterative application workflows

Best Practices

When designing loops:
  • Define a clear termination condition.
  • Make sure the loop can eventually exit.
  • Update the state used by the continuation decision.
  • Keep the loop body focused.
  • Avoid unnecessary nested loops.
  • Make progress explicit.
  • Keep loop conditions readable.
  • Test zero, one, multiple, and terminating iterations.
  • Test the workflow state after each iteration where appropriate.
  • Avoid depending on model output alone for termination.
  • Keep external operations inside tools or connection-backed tools.
  • Define failure behavior for important loop operations.

Current BindAI V1 Scope

BindAI V1 supports loop-based workflow orchestration. Loops can currently be combined with:
  • Agent nodes
  • Tool nodes
  • Condition nodes
  • Connection-backed tools
  • Workflow variables
  • Workflow state
  • Memory-enabled agents
  • Knowledge-enabled agents
  • Parallel and Join workflow structures
  • Human Tasks
Loops provide the workflow control-flow mechanism for repeated execution.

Deferred Features

The following are outside the verified V1 loop feature set:
  • Advanced retry policies
  • Advanced timeout policies
  • Workflow scheduling
  • Automation triggers
  • Distributed loop execution
  • Advanced loop monitoring
  • Advanced cancellation APIs
  • Advanced loop administration
These should only be documented as implemented features after they are actually available and verified.

API Accuracy

This documentation intentionally does not assume specific public APIs such as:
or a particular predicate signature unless those APIs are verified in the current BindAI implementation. The verified V1 capability is loop-based workflow execution through the workflow runtime and Studio workflow configuration. When a concrete public loop API is exposed, documentation should include:
  1. The actual import path.
  2. The actual constructor or factory.
  3. The actual parameters.
  4. The loop decision behavior.
  5. The loop-body behavior.
  6. The exit behavior.
  7. Tests demonstrating the behavior.

Summary

Loops allow BindAI workflows to repeat intentional workflow logic. A typical loop follows:
Loops are useful for collections, batches, pagination, iterative validation, repeated agent processing, repeated tool execution, and other intentional repeated operations. The most important loop requirement is a clear path toward termination.
Loops repeat intentional workflow behavior; the loop body should make measurable progress toward its exit condition.
Specific loop APIs should only be documented after they are verified against the current BindAI implementation and tests.